package com.peaksport.pkms.leanrtest1.service;

import java.net.URLDecoder;

import org.apache.servicecomb.pack.omega.transaction.annotations.Compensable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.peaksport.framework.base.dao.IBaseDAO;
import com.peaksport.framework.base.service.BillBaseService;
import com.peaksport.framework.exception.PKBizException;

@Service
public class TestPackSaga1Service extends BillBaseService{

	@Override
	public IBaseDAO<?> getDAO() {
		return null;
	}

	@Compensable(compensationMethod="auditBillEntry_cancel")
	@Transactional
	public void auditBillEntry(String pk, boolean isException, boolean isExceptionInCancel) {
		pk = URLDecoder.decode(pk);
		String checkSql = "select FLineStatus from t_tst_billentry where FParentId='" + pk + "'";
		boolean b = isExistsForNative(checkSql);
		if (!b) throw PKBizException.throwException("不存在分录记录[%s]", pk);
		String updSql= "update t_tst_billentry set FLineStatus=99 where FParentId='" + pk + "'";
		executeSqlForNative(updSql.toString());
		System.out.println("auditBillEntry");
		if(isException) throw PKBizException.throwException("审核分录方法auditBillEntry异常");
		
	}
	
	@Transactional
	public void auditBillEntry_cancel(String pk, boolean isException, boolean isExceptionInCancel) {
		pk = URLDecoder.decode(pk);
		String updSql= "update t_tst_billentry set FLineStatus=0 where FParentId='" + pk + "'and FLineStatus=99";
		executeSqlForNative(updSql.toString());
		System.out.println("auditBillEntry_cancel");
		if(isExceptionInCancel) throw PKBizException.throwException("审核分录cancel方法auditBillEntry_cancel异常");
	}
}
